#region using
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;

using XmlGenSharp.Lib.Utility;
#endregion

#region pragmas
#pragma warning disable 0219
#endregion

namespace Demo.DbmlReader
{
  public partial class ColumnType
  {
    // Public Constants

    #region Public Constants
    public const int BooleanVal = 1;
    public const int IntVal = 2;
    public const int SmallIntVal = 3;
    public const int TinyIntVal = 4;
    public const int NVarCharVal = 5;
    public const int TextVal = 6;

    public static readonly ColumnType Unknown = new ColumnType("Unknown", 0);
    public static readonly BooleanColumnType Boolean = new BooleanColumnType("Boolean", 1, "tinyint");
    public static readonly IntColumnType Int = new IntColumnType("Int", 2, "int");
    public static readonly SmallIntColumnType SmallInt = new SmallIntColumnType("SmallInt", 3, "smallint");
    public static readonly TinyIntColumnType TinyInt = new TinyIntColumnType("TinyInt", 4, "tinyint");
    public static readonly NVarCharColumnType NVarChar = new NVarCharColumnType("NVarChar", 5, "nvarchar");
    public static readonly TextColumnType Text = new TextColumnType("Text", 6, "text");
    #endregion

    // Public Constructors

    #region ColumnType(string text, int val)
    public ColumnType(string text, int val)
    {
      InnerText = text;
      Value = val;
    }
    #endregion

    #region ColumnType(string text, int val, string sqlDataType)
    public ColumnType(string text, int val, string sqlDataType)
    {
      InnerText = text;
      Value = val;
      SqlDataType = sqlDataType;
    }
    #endregion

    // Public Properties

    #region InnerText
    public string InnerText
    {
      get;
      protected set;
    }
    #endregion

    #region Value
    public int Value
    {
      get;
      protected set;
    }
    #endregion

    #region IsUnknown
    public bool IsUnknown
    {
      get
      {
        return Value == 0;
      }
    }
    #endregion

    #region SqlDataType
    public string SqlDataType
    {
      get;
      protected set;
    }
    #endregion

    // Public Methods

    #region ToString()
    public override string ToString()
    {
      return InnerText;
    }
    #endregion

    #region GetHashCode()
    public override int GetHashCode()
    {
      return Value;
    }
    #endregion

    #region Equals(object o)
    public override bool Equals(object o)
    {
      if (o.GetType() == typeof(int))
        return this.Value == (int) o;

      if (o.GetType() == typeof(string))
        return this.InnerText == (string) o;

      if (o.GetType() == typeof(ColumnType))
        return this.Value == ((ColumnType) o).Value;

      return false;
    }
    #endregion

    // Public Static Methods

    #region Parse(string text)
    public static ColumnType Parse(string text)
    {
      if (text == null)
        return Unknown;

      switch (text.ToLower())
      {
        case "boolean":
          return Boolean;

        case "int":
          return Int;

        case "smallint":
          return SmallInt;

        case "tinyint":
          return TinyInt;

        case "nvarchar":
          return NVarChar;

        case "text":
          return Text;

        default:
          return Unknown;
      }
    }
    #endregion

    #region Find(string text)
    public static ColumnType Find(string text)
    {
      return Parse(text);
    }
    #endregion

    #region Find(int val)
    public static ColumnType Find(int val)
    {
      switch (val)
      {
        case 1:
          return Boolean;

        case 2:
          return Int;

        case 3:
          return SmallInt;

        case 4:
          return TinyInt;

        case 5:
          return NVarChar;

        case 6:
          return Text;

        default:
          return Unknown;
      }
    }
    #endregion

    // Public Operators

    #region operator ColumnType(int val)
    public static implicit operator ColumnType(int val)
    {
      return Find(val);
    }
    #endregion

    #region operator ColumnType(string val)
    public static implicit operator ColumnType(string val)
    {
      return Find(val);
    }
    #endregion

    #region operator int(ColumnType val)
    public static implicit operator int(ColumnType val)
    {
      return val.Value;
    }
    #endregion

    #region operator string(ColumnType val)
    public static implicit operator string(ColumnType val)
    {
      return val.InnerText;
    }
    #endregion

    #region operator ==(ColumnType lhs, ColumnType rhs)
    public static bool operator ==(ColumnType lhs, ColumnType rhs)
    {
      return lhs.Value == rhs.Value;
    }
    #endregion

    #region operator !=(ColumnType lhs, ColumnType rhs)
    public static bool operator !=(ColumnType lhs, ColumnType rhs)
    {
      return lhs.Value != rhs.Value;
    }
    #endregion

    #region operator ==(ColumnType lhs, int rhs)
    public static bool operator ==(ColumnType lhs, int rhs)
    {
      return lhs.Value == rhs;
    }
    #endregion

    #region operator !=(ColumnType lhs, int rhs)
    public static bool operator !=(ColumnType lhs, int rhs)
    {
      return lhs.Value != rhs;
    }
    #endregion

    #region operator ==(ColumnType lhs, string rhs)
    public static bool operator ==(ColumnType lhs, string rhs)
    {
      return lhs.InnerText.ToLower() == rhs.ToLower();
    }
    #endregion

    #region operator !=(ColumnType lhs, string rhs)
    public static bool operator !=(ColumnType lhs, string rhs)
    {
      return lhs.InnerText.ToLower() != rhs.ToLower();
    }
    #endregion

    // Public Classes

    #region class BooleanColumnType
    public partial class BooleanColumnType : ColumnType
    {
      // Public Constructors

      #region BooleanColumnType(string text, int val)
      public BooleanColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region BooleanColumnType(string text, int val, string sqlDataType)
      public BooleanColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion

    #region class IntColumnType
    public partial class IntColumnType : ColumnType
    {
      // Public Constructors

      #region IntColumnType(string text, int val)
      public IntColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region IntColumnType(string text, int val, string sqlDataType)
      public IntColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion

    #region class SmallIntColumnType
    public partial class SmallIntColumnType : ColumnType
    {
      // Public Constructors

      #region SmallIntColumnType(string text, int val)
      public SmallIntColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region SmallIntColumnType(string text, int val, string sqlDataType)
      public SmallIntColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion

    #region class TinyIntColumnType
    public partial class TinyIntColumnType : ColumnType
    {
      // Public Constructors

      #region TinyIntColumnType(string text, int val)
      public TinyIntColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region TinyIntColumnType(string text, int val, string sqlDataType)
      public TinyIntColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion

    #region class NVarCharColumnType
    public partial class NVarCharColumnType : ColumnType
    {
      // Public Constructors

      #region NVarCharColumnType(string text, int val)
      public NVarCharColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region NVarCharColumnType(string text, int val, string sqlDataType)
      public NVarCharColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion

    #region class TextColumnType
    public partial class TextColumnType : ColumnType
    {
      // Public Constructors

      #region TextColumnType(string text, int val)
      public TextColumnType(string text, int val) : base(text, val)
      {
      }
      #endregion

      #region TextColumnType(string text, int val, string sqlDataType)
      public TextColumnType(string text, int val, string sqlDataType) : base(text, val, sqlDataType)
      {
      }
      #endregion
    }
    #endregion
  }
}